const { regeneratorRuntime, connect, P } = global

Page(global.connect(
  state => ({
    ...state.globalReducer
  }),
  dispatch => ({
    handleRoute: global.handleRoute,
    handleLicon1Tap(e) {
      console.log('handleLicon1Tap', e)
      wx.navigateBack()
    },
    handleTap(e) {
      console.log('handleTap', e)
      const { route, avatar } = e.currentTarget.dataset
      if (route) {
        this.handleRoute(e)
      }
      if (avatar) {
        this.handleAvatar(e)
      }
    },
    handleAvatar(e) {
      console.log('handleAvatar', e)
    },
    asyncAuthInfo(data) {
      dispatch(global.globalReducer.asyncAuthInfo(data))
    }
  })
)(P({
  data: {
    isUpdate: true,
    name: '刘师傅',
    identifyNum: '440981818188181881',
    locationCity: '广东省深圳市',
    serviceArea: '南山区/宝安区',
    cityPartner: '2',

    // ---
    multiArray: [
      ['广东省', '湖南省'],
      ['深圳市', '惠州市', '广州市', '佛山市', '中山市']
    ],
    multiIndex: [0, 0],
    prevMultiIndex: [0, 0],
    objectMultiArray: [
      [
        { id: 0, name: '广东省' },
        { id: 1, name: '湖南省' }
      ],
      [
        { id: 0, name: '深圳市', province_id: 0 },
        { id: 1, name: '惠州市', province_id: 0 },
        { id: 2, name: '广州市', province_id: 0 },
        { id: 3, name: '佛山市', province_id: 0 },
        { id: 3, name: '中山市', province_id: 0 },

        { id: 4, name: 'h1', province_id: 1 },
        { id: 5, name: 'h2', province_id: 1 },
        { id: 6, name: 'h3', province_id: 1 },
        { id: 7, name: 'h4', province_id: 1 },
        { id: 8, name: 'h5', province_id: 1 },
      ]
    ],
    // ---
    areas: ['南山区', '宝安区', '福田区', '罗湖区', '龙华区', '龙岗区', '大鹏新区', '坪山区'],
    areaIndex: 1,
  },
  onLoad() {
    console.log(`${this.route} onLoad`)
  },
  handleLogout() {
    wx.removeStorageSync('openid')
    wx.reLaunch({
      url: "/pages/login/login"
    })
  },
  handleInput(e) {
    const { field } = e.currentTarget.dataset
    const obj = {}
    obj[field] = e.detail.value
    this.setData(obj)
  },
  handlePartner(e){
    global.handleRoute({ route: 'partner' })
  },
  // 

  bindMultiPickerChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
    const { multiArray, multiIndex } = this.data
    this.asyncAuthInfo({
      province: multiArray[0][multiIndex[0]],
      city: multiArray[1][multiIndex[1]],
    })
  },
  bindMultiPickerColumnChange(e) {
    console.log('修改的列为', e.detail.column, '，值为', e.detail.value)
    const { multiArray, multiIndex, objectMultiArray } = this.data

    // 列
    switch (e.detail.column) {
      case 0:
        multiArray[1] = objectMultiArray[1].filter(i => i.province_id === e.detail.value).map(i => i.name)
        multiIndex[1] = 0
        break;
      case 1:
        break;
      default:
        break;
    }
    multiIndex[e.detail.column] = e.detail.value
    // console.log(multiIndex, multiArray)
    this.setData({ multiArray, multiIndex })
  },
  handleAreaChange(e) {
    console.log('handleAreaChange', e)
    const areaIndex = Number(e.detail.value) || 0
    this.setData({ areaIndex })
    this.asyncAuthInfo({
      service_area: this.data.areas[areaIndex]
    })
  }
})))